<template>
  <el-button type="primary" @click="$ses.pushByNameResId('ChangeHomeWorksStuList',{homeworkId:id})">修改授权学生
  </el-button>
  <el-table :data="homeWorkStuStatus" style="width: 100%" max-height="250">
    <el-table-column prop="StuClass" label="班级" width="150"/>
    <el-table-column prop="StuName" label="学生姓名" width="120"/>
    <el-table-column prop="StuNum" label="学号" width="120"/>
    <el-table-column :formatter="StatusFormat" prop="Status" label="状态" width="120"/>
    <el-table-column prop="FileList" label="文件" width="120">
      <template #default="scope">
        <div v-for="(item,index) in scope.row.FileList">
          <a :download="getNameFromUrl(item)" :href="'/api/GetHomeWorkFileByUrl/'+item+'?tk='+fileUpHead.tk"  v-text="getNameFromUrl(item)"></a>
          <br>
        </div>

      </template>
    </el-table-column>
    <el-table-column prop="Score" label="分数" width="120"/>
    <el-table-column label="Operations" width="300">
      <template #default="scope">
        <el-button
            type="text"
            size="small"
            :disabled="scope.row.FileList===null"
            @click.prevent="$ses.pushByNameResId('pre_view_homework',{fileList:scope.row.FileList,score:scope.row.Score,id:scope.row.StuHomeworkId})"
        >
          预览
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import axios from "axios";

export default {
  name: "HomeWorkStatus",
  data() {
    return {
      homeWorkStuStatus: [],
      statusMap: new Map(),
      fileUpHead:{},
      id:''
    }
  },
  created() {
    var parse = JSON.parse(window.localStorage.getItem('zjxClass_teacherinfo'));
    this.fileUpHead = {
      'tk': parse.Token
    }
    this.id = this.$ses.getSesWithParse(this.$route.query.resId).id
    axios.get('/api/teacher/GetHomeWorkFileAndStudentListByHomeWorkId', {
      params: {
        id: this.id
      }
    }).then((res) => {
        this.homeWorkStuStatus = res.data
    })


    //未交0/未审阅1/退回3/已审阅2
    this.statusMap.set('0','未提交')
    this.statusMap.set('1','未审阅')
    this.statusMap.set('3','退回')
    this.statusMap.set('2','已审阅')
  },
  methods: {
    handleEdit(scope){
      console.log(scope.row)
    },
    getNameFromUrl(item){
      return item.split("_zjx_")[1]
    },
    setUpData() {
    },
    StatusFormat(row, column, cellValue, index){
      return this.statusMap.get(cellValue)
    }
  }
}
</script>

<style scoped>

</style>